<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>支付</title>
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  <script src="https://unpkg.com/qs@6.10.3/dist/qs.js"></script>
  <script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
</head>
<body>

  <div style="text-align:center;padding:50px 20px;">
    正在支付，请勿关闭页面...
  </div>
  
  <script>
// http://localhost:8080/static/wxpay.html?code=001DVZll2b2e994wM4ol2izfdn1DVZlA&state=202205131620337341595926681
var params = Qs.parse(window.location.search.substring(1));
var code = params.code;
var orderId = params.state;

/**
 * FIXME:
 */
// var apiServer = 'http://200.200.200.104:8001';
// var apiServer = 'http://192.168.66.30';
var apiServer = 'http://hs.tssdeyy.com';
var payServer = 'http://www.tssdeyy.com/hesuan';

var zfdata = {};
var zf = {};

const instance = axios.create({
  baseURL: apiServer,
  timeout: 30000,
  headers: {
    "Content-Type": "application/json",
  }
});

(function() {
  instance.post('/api/Bank/Pay', {
    code: code,
    orders_id: orderId,
  }).then(function(res) {
    var data = res.data;
    if (data.success) {
      // {"mac":"MERCHANTID=105000080621951&POSID=034631259&BRANCHID=130000000&ORDERID=202205131752113312107502111&PAYMENT=0.01&CURCODE=01&TXCODE=530590&REMARK1=o9crB07dpCQzQVZanh8dvZhe8u0k&REMARK2=130282199207255111&TYPE=1&PUB=c6077ec51863c76522fe66e7020111&GATEWAY=0&CLIENTIP=200.200.200.104&REGINFO=%u5b5f%u674e%u8f89-15081515272-130282199207255111&PROINFO=130282199207255111&REFERER=&TIMEOUT=20220513175807&TRADE_TYPE=JSAPI&SUB_APPID=wx32c0dfcb4dc3fc23&SUB_OPENID=o9crB07dpCQzQVZanh8dvZhe8u0k","pay":"{\"MERCHANTID\":\"105000080621951\",\"POSID\":\"034631259\",\"BRANCHID\":\"130000000\",\"ORDERID\":\"202205131752113312107502111\",\"PAYMENT\":\"0.01\",\"CURCODE\":\"01\",\"REMARK1\":\"o9crB07dpCQzQVZanh8dvZhe8u0k\",\"REMARK2\":\"130282199207255111\",\"TXCODE\":\"530590\",\"MAC\":\"26aa592b98e19aa5ea4394e053323bed\",\"TYPE\":\"1\",\"PUB\":\"c6077ec51863c76522fe66e7020111\",\"GATEWAY\":\"0\",\"CLIENTIP\":\"200.200.200.104\",\"REGINFO\":\"孟李辉-15081515272-130282199207255111\",\"PROINFO\":\"130282199207255111\",\"REFERER\":\"\",\"TIMEOUT\":\"20220513175807\",\"TRADE_TYPE\":\"JSAPI\",\"SUB_APPID\":\"wx32c0dfcb4dc3fc23\",\"SUB_OPENID\":\"o9crB07dpCQzQVZanh8dvZhe8u0k\"}","data":"\r\n{\r\n\t\"SUCCESS\":\"true\",\r\n\t\"ERRCODE\":\"000000\",\r\n\t\"ERRMSG\":\"\",\r\n\t\"TXCODE\":\"530590\",\r\n\t\"appId\":\"wx32c0dfcb4dc3fc23\",\r\n\t\"timeStamp\":\"1652435578\",\r\n\t\"nonceStr\":\"cA79eKenGUBZRTW5cecrHZWk8XCOmtzT\",\r\n\t\"package\":\"prepay_id=wx13175258444173823a1007bc2bc3f80000\",\r\n\t\"signType\":\"RSA\",\r\n\t\"paySign\":\"NNfxvh7D+fzinHWYfaEQv4kUo400n1P3Vy53rm3nN6RS5KNYt6a2riTj6NEF9lhsMSghG1YXUP12WKLxYMpCDv3ZeAXLNFTK/vJGjv+Wvf6oGht2pljUI8HRCfIP03nIj3VrWpIkMNR3k9Hi3/ix+vnBTaE4VVFVyZPP5lC8jCcvS9fmWUM67epU7DQhy7ZtVkbNOwgsV7UQCeQxm93599f0TzJLfBZqu853CXwHeEfLSGRWn/s01OaPVOP+Q3nfFpbgcNKREFZMyj4dCpkSy6ecmIkmG+jUHIEJhjJa0gMFeAYUTkSI26xzsqKrWpBUFC4BA8c704E+ba1oy4+2xA==\",\r\n\t\"partnerid\":\"255714717\",\r\n\t\"prepayid\":\"\",\r\n\t\"mweb_url\":\"\"\t\r\n}","jhPayw":"{\"SUCCESS\":\"true\",\"ERRCODE\":\"000000\",\"ERRMSG\":\"\",\"TXCODE\":\"530590\",\"appId\":\"wx32c0dfcb4dc3fc23\",\"timeStamp\":\"1652435578\",\"nonceStr\":\"cA79eKenGUBZRTW5cecrHZWk8XCOmtzT\",\"package\":\"prepay_id=wx13175258444173823a1007bc2bc3f80000\",\"signType\":\"RSA\",\"paySign\":\"NNfxvh7D+fzinHWYfaEQv4kUo400n1P3Vy53rm3nN6RS5KNYt6a2riTj6NEF9lhsMSghG1YXUP12WKLxYMpCDv3ZeAXLNFTK/vJGjv+Wvf6oGht2pljUI8HRCfIP03nIj3VrWpIkMNR3k9Hi3/ix+vnBTaE4VVFVyZPP5lC8jCcvS9fmWUM67epU7DQhy7ZtVkbNOwgsV7UQCeQxm93599f0TzJLfBZqu853CXwHeEfLSGRWn/s01OaPVOP+Q3nfFpbgcNKREFZMyj4dCpkSy6ecmIkmG+jUHIEJhjJa0gMFeAYUTkSI26xzsqKrWpBUFC4BA8c704E+ba1oy4+2xA==\",\"prepayid\":\"\",\"mweb_url\":\"\"}"}
      var macStr = data.data.mac;
      var payStr = data.data.pay;
      var dataStr = data.data.data;
      var jhPaywStr = data.data.jhPayw;

      // ERRCODE: "000000"
      // ERRMSG: ""
      // SUCCESS: "true"
      // TXCODE: "530590"
      // appId: "wx32c0dfcb4dc3fc23"
      // mweb_url: ""
      // nonceStr: "cA79eKenGUBZRTW5cecrHZWk8XCOmtzT"
      // package: "prepay_id=wx13175258444173823a1007bc2bc3f80000"
      // paySign: "NNfxvh7D+fzinHWYfaEQv4kUo400n1P3Vy53rm3nN6RS5KNYt6a2riTj6NEF9lhsMSghG1YXUP12WKLxYMpCDv3ZeAXLNFTK/vJGjv+Wvf6oGht2pljUI8HRCfIP03nIj3VrWpIkMNR3k9Hi3/ix+vnBTaE4VVFVyZPP5lC8jCcvS9fmWUM67epU7DQhy7ZtVkbNOwgsV7UQCeQxm93599f0TzJLfBZqu853CXwHeEfLSGRWn/s01OaPVOP+Q3nfFpbgcNKREFZMyj4dCpkSy6ecmIkmG+jUHIEJhjJa0gMFeAYUTkSI26xzsqKrWpBUFC4BA8c704E+ba1oy4+2xA=="
      // prepayid: ""
      // signType: "RSA"
      // timeStamp: "1652435578"
      zfdata = JSON.parse(jhPaywStr);
      // BRANCHID: "130000000"
      // CLIENTIP: "200.200.200.104"
      // CURCODE: "01"
      // GATEWAY: "0"
      // MAC: "26aa592b98e19aa5ea4394e053323bed"
      // MERCHANTID: "105000080621951"
      // ORDERID: "202205131752113312107502111"
      // PAYMENT: "0.01"
      // POSID: "034631259"
      // PROINFO: "130282199207255111"
      // PUB: "c6077ec51863c76522fe66e7020111"
      // REFERER: ""
      // REGINFO: "孟李辉-15081515272-130282199207255111"
      // REMARK1: "o9crB07dpCQzQVZanh8dvZhe8u0k"
      // REMARK2: "130282199207255111"
      // SUB_APPID: "wx32c0dfcb4dc3fc23"
      // SUB_OPENID: "o9crB07dpCQzQVZanh8dvZhe8u0k"
      // TIMEOUT: "20220513175807"
      // TRADE_TYPE: "JSAPI"
      // TXCODE: "530590"
      // TYPE: "1"
      zf = JSON.parse(payStr);

      startPay();
    }
  })
})();

function startPay() {
  if (typeof WeixinJSBridge == "undefined") {
    if (document.addEventListener) {
      document.addEventListener('WeixinJSBridgeReady', wxPay, false);
    } else if (document.attachEvent) {
      document.attachEvent('WeixinJSBridgeReady', wxPay);
      document.attachEvent('onWeixinJSBridgeReady', wxPay);
    }
  } else {
    wxPay();
  }
}

function wxPay() {
  var wxdata = zfdata;
  WeixinJSBridge.invoke('getBrandWCPayRequest',
    {
      "appId": wxdata.appId,     //公众号名称，由商户传入
      "timeStamp": wxdata.timeStamp,         //时间戳，自1970年以来的秒数
      "nonceStr": wxdata.nonceStr, //随机串
      "package": wxdata.package,
      "signType": wxdata.signType,         //微信签名方式：
      "paySign": wxdata.paySign //微信签名
    },
    function(res) {
      console.log('=== wx getBrandWCPayRequest: ', res);

      if (res.err_msg == "get_brand_wcpay_request:ok") {
        /**
         * TODO:
         */
        instance.post("/api/Bank/PaySuccess?orders_id=" + orderId).then(function (res) {
          console.log('=== /api/Bank/PaySuccess: ', res.data);

          if (res.data) {
            // alert('支付成功');
            window.location.href = payServer + '/#/pages/hesuanyuyue/records/index'
          } else {
            alert('支付失败。error2')
          }
        });

        if (typeof message !== 'undefined' && message.success) {
          message.success('支付成功', 5) //可以正常提示
        } else {
          alert('支付成功') //ios 不执行
        }

        /**
         * FIXME:
         */
        window.location.href = payServer + '/#/pages/hesuanyuyue/records/index'
        
      } else {
        alert('支付失败。error1')
      }
    }
  );
}
  </script>
</body>
</html>